<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 1.求最大值
    // function getMax(x, y) {
    //   return x > y ? x : y
    // }
    // let max = getMax(1,2)
    // console.log(max)

    // 2.求任意数组的最大值
    // function getMax(arr = []) {
    //   let max = arr[0]
    //   for (let i = 0; i < arr.length; i++) {
    //     if (max < arr[i]) {
    //       max = arr[i]
    //     }
    //   }
    //   return max
    // }
    // let maxSum = getMax([2, 45, 654])
    // console.log(maxSum)
    
    // 3.求最大值和最小值
    function getArrValues(arr = []) {
      let max = arr[0]
      let min = arr[0]
      for (let i = 0; i < arr.length; i++) {
        if (max < arr[i]) {
          max = arr[i]
        }
        if (min > arr[i]) {
          min = arr[i]
        }
      }
      return [max, min]
    }
    let newArr = getArrValues([2, 45, 654])
    console.log(newArr)
  </script>
</body>
</html>